package com.navinfo.data.journal;


import org.apache.commons.csv.CSVFormat;
import org.apache.commons.csv.CSVRecord;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;

public class CsvUtils {
    private static final Logger LOGGER = LoggerFactory.getLogger(CsvUtils.class);

    public static void main(String[] args) {
        Reader in = null;
        try {
            in = new FileReader("E:\\qingqidata\\10019411330\\10019411330驾驶行为分析(2018-11-11-00-00-00至2018-11-12-00-00-00).csv");
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            LOGGER.error("FileNotFoundException");
        }
        Iterable<CSVRecord> records = null;
        try {
            records = CSVFormat.RFC4180.withFirstRecordAsHeader().parse(in);
        } catch (IOException e) {
            e.printStackTrace();
            LOGGER.error("IOException");
        }
        for (CSVRecord record : records) {

            double routeStartLatitude =  Double.parseDouble(record.get("routeStartLatitude"))/1000000;
            double routeStartLongitude =  Double.parseDouble(record.get("routeStartLongitude"))/1000000;
            double routeEndLatitude =  Double.parseDouble(record.get("routeEndLatitude"))/1000000;
            double routeEndLongitude =  Double.parseDouble(record.get("routeEndLongitude"))/1000000;
            LOGGER.info(routeStartLatitude+"--------"+routeStartLongitude+
                    "||"+routeEndLatitude+"--------"+routeEndLongitude);
        }
    }
}
